package com.blog.quartzjob;

import com.blog.mapper.StatisticsMapper;
import com.blog.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author jiafujun
 * 2020-06-22 17:52:53
 **/
@Component
@EnableScheduling
public class QuartzServer {

    @Autowired
    private StatisticsMapper statisticsMapper;

    /**
     * 删除33天以前的数据，缓解表压力。毕竟是个轻型数据库，经不起折腾。
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void delStatistics() {
        String delTime = DateUtil.getStrDate(DateUtil.getDateToDateNum(new Date(), -33));
        statisticsMapper.delByTime(delTime);
    }
}
